package com.besovideo.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RadioButton;
import android.widget.TextView;

import com.besovideo.mpu.R;

public class RadioListViewAdapter extends BaseAdapter {

	private String[] mTitles;
	private int[] mValues;
	private Context mContext;
	private LayoutInflater mInflater;
	private int selectIndex = -1;
	public int width = 0;
	public int higth = 0;
	public int splitCol = 6;
	public int splitHor = 6;

	public RadioListViewAdapter(Context context, String[] titles, int values[]) {
		this.mContext = context;
		this.mTitles = titles;
		this.mValues = values;
		mInflater = (LayoutInflater) mContext
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);// LayoutInflater.from(mContext);
	}

	@Override
	public int getCount() {
		return mTitles.length;
	}

	@Override
	public Object getItem(int position) {
		return position;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = mInflater
					.inflate(R.layout.list_view_item_radio, null);
			holder.mTitle = (TextView) convertView
					.findViewById(R.id.menu_radio_title);
			holder.mValue = (RadioButton) convertView
					.findViewById(R.id.menu_radio_button);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		if (position == selectIndex) {
			convertView.setSelected(true);
		} else {
			convertView.setSelected(false);
		}

		holder.mTitle.setText(mTitles[position]);
		holder.mValue.setChecked((mValues[position] == 1 ? true : false));

		return convertView;
	}

	public class ViewHolder {
		private TextView mTitle;
		private RadioButton mValue;
	}

	public void setSelectIndex(int i) {
		selectIndex = i;
	}

}